package com.zkt.auth.domain.service.impl;

import com.zkt.auth.domain.entity.AuthRolePermissionBO;
import com.zkt.auth.domain.service.AuthRolePermissionDomainService;
import com.zkt.auth.infra.basic.entity.AuthRolePermission;
import com.zkt.auth.infra.basic.service.IAuthRolePermissionService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

/**
 * @author 赵开泰
 * @program jc-club
 * @date 2024/9/30
 * @description 角色权限关系领域服务
 **/

@Service
@Slf4j
public class AuthRolePermissionDomainServiceImpl implements AuthRolePermissionDomainService {
	
	@Resource
	private IAuthRolePermissionService authRolePermissionService;
	
	/**
	 * 新增角色权限关系
	 *
	 * @param authRolePermissionBO 角色权限关系信息
	 * @return 是否成功
	 */
	@Override
	public Boolean add(AuthRolePermissionBO authRolePermissionBO) {
		List<AuthRolePermission> authRolePermissionList = new LinkedList<>();
		Long roleId = authRolePermissionBO.getRoleId();
		
		authRolePermissionBO.getPermissionIdList().forEach(permissionId -> {
			AuthRolePermission authRolePermission = new AuthRolePermission();
			
			authRolePermission.setRoleId(roleId);
			authRolePermission.setPermissionId(permissionId);
			
			authRolePermissionList.add(authRolePermission);
		});
		
		return authRolePermissionService.saveBatch(authRolePermissionList);
	}
}